<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin=new admin();
$id=$_GET['id'];
$url=$_GET['url'];

$admin->canView($url);


$page=$admin->getPageInformation($id);
$is_blog=($page['is_blog']==1) ? true : false;
?>
<div class="oneem">
    <form class="inline" action="/admin/resources/php/requests/actions/save-page.php">
    <input type="hidden" class="settings" value='{"buttonWaitingValue":"Updating","updateNode":"#response"}' />	
    <input type="hidden" name="page_id" id="page_id" value="<?php echo($id); ?>" />
    <input type="submit" class="button" style="float:right;" value="Save changes" />
<h1 style="margin-bottom:1em;">Pages &raquo;&raquo; <?php echo($page['text']); ?></h1>

<div class="qt-tab-wrapper" style="height:90%;">
<ul class="qt">
<li><a href="#st1-pages" id="st1" class="qta">Page Settings</a></li>
<li><a href="#st2-pages" id="st2" class="qta">Page Meta Data</a></li>
<?php if(!$is_blog) { ?>
<li><a href="#st3-pages" id="st3" class="qta">Page Content</a></li>
<?php } ?>
</ul>
<div id="st1-pages" class="qt-content-container" style="display:none;">

<table width="70%" cellspacing="4" cellpadding="4">
    	
    <tr valign="top">
    	<td width="20%"><strong>Page Name:</strong></td>
    	<td width="80%"><input type="text" class="form-field req" name="page_text" id="page_text" style="width:250px;" value="<?php echo($page['text']); ?>" />  <span class="hint">(name to appear in the site menu)</span></td>
    </tr>
    <tr valign="top">
    	<td><strong>Cache Page:</strong></td>
    	<td><select type="text" class="form-field req" name="page_cache" id="page_cache" style="width:56px;"><?php echo($admin->selectYesNo($page['cache'])); ?></select> <span class="hint">(if page relies on dynamic elements i.e searching / pagination then it should not be cached)</span></td>
    </tr>
    <tr valign="top">
        	<td><strong>Active:</strong></td>
            <td><select class="form-field" name="page_active" id="page_active" style="width:56px;"><?php echo($admin->selectYesNo($page['active'])); ?></select>  <span class="hint">Is the page active?</span></td>
        </tr>
        <tr valign="top">
    	<td><strong>Page URL:</strong></td>
    	<td><input type="text" class="form-field req" name="page_url" id="page_url" style="width:250px;" value="<?php echo($page['url']); ?>" /> <span class="hint">(with leading / trailing slashes)</span></td>
    </tr>	
    <tr valign="top">
    	<td><strong>Page H1 Heading:</strong></td>
    	<td><input type="text" class="form-field" name="page_heading" id="page_heading" style="width:250px;" value="<?php echo($page['heading']); ?>" /> <span class="hint">(recommended)</span></td>
    </tr>	
    
    <tr valign="top">
    	<td><strong>Menu Order:</strong></td>
    	<td><input type="text" class="form-field req" name="page_order" id="page_order" style="width:50px;" value="<?php echo($page['order']); ?>" /> <span class="hint">(order in the menu [low to high])</span></td>
    </tr>
    <tr valign="top">
        	<td><strong>Parent:</strong></td>
            <td><select class="form-field" name="page_parent" id="page_parent" style="width:250px;"><?php echo(get_parent_pages_as_opts($page['parent'])); ?></select> <span class="hint">Is the page part of the sub menu navigation </span></td></tr>
    
     <tr valign="top">
    	<td><strong>Include Sidebar:</strong></td>
    	<td><select class="form-field" name="page_include_sidebar" id="page_include_sidebar" style="width:56px;">
        	<?php echo($admin->selectYesNo($page['include_sidebar'])); ?>
        </select> <span class="hint">Include the sidebar?</span></td>
    </tr>
    <tr valign="top">
    	<td><strong>Is Blog Page:</strong></td>
    	<td><select class="form-field" name="page_is_blog" id="page_is_blog" style="width:56px;">
        	<?php echo($admin->selectYesNo($page['is_blog'])); ?>
        </select> <span class="hint">Is the page the sites blog?</span></td>
    </tr>
    <tr valign="top">
    	<td><strong>Include In Nav:</strong></td>
    	<td><select class="form-field" name="page_include_in_nav" id="page_include_in_nav" style="width:56px;">
        	<?php echo($admin->selectYesNo($page['include_in_nav'])); ?>
        </select> <span class="hint">Show in site navigation?</span></td>
    </tr>
    
    <tr valign="top">
        	<td><strong>Require Logged In User:</strong></td>
            <td><select class="form-field" name="page_requires_auth" id="page_requires_auth" style="width:56px;"><?php echo($admin->selectYesNo($page['require_auth'])); ?></select> <span class="hint">(relies on user componant)</span></td>
    </tr> 
    <tr valign="top">
        	<td><strong>Require Group(s)<br />(read access):</strong></td>
            <td>
            	<div class="form-field" style="height:100px;overflow-y:hidden;overflow-x:auto;width:250px;">
                <ul>
				<?php
					$groups=$admin->getGroups();
					foreach($groups as $row) {
						$checked=(in_array($row['_id'],$page['groups'])) ? ' checked="checked"' : '';
						echo('<li><input type="checkbox" name="page_group[]" value="'.$row['_id'].'"'.$checked.' /> <strong>'.$row['label'].'</strong></li>');	
					}
				
				?>	
                </ul>
                </div>
                <p class="hint">No groups selected means all users can view.</p>
            </td>
        </tr>
    
      
</table>
</div>
<div id="st2-pages" class="qt-content-container" style="display:none;">
<table width="100%" cellspacing="4" cellpadding="4">
<tr valign="top">
    	<td width="13%"><strong>Page title:</strong></td>
    	<td width="87%"><input type="text" class="form-field req" name="meta_page_title" id="meta_page_title" style="width:450px;" value="<?php echo($page['meta']['title']); ?>" /> <span class="hint">(60 chars recommended)</span></td>
    </tr>
    <tr valign="top">
    	<td><strong>Page description:</strong></td>
    	<td><input type="text" class="form-field" name="meta_page_description" id="meta_page_description" style="width:450px;" value="<?php echo($page['meta']['description']); ?>" /> <span class="hint">(150 chars recommended)</span></td>
    </tr>
    <tr valign="top">
    	<td><strong>Page keywords:</strong></td>
    	<td><input type="text" class="form-field" name="meta_page_keywords" id="meta_page_keywords" style="width:450px;" value="<?php echo($page['meta']['keywords']); ?>" /> <span class="hint">(comma separate)</span></td>
    </tr>
    <tr valign="top">
    	<td><strong>Custom meta-tags:</strong></td>
    	<td><textarea class="form-field" name="meta_page_custom" id="meta_page_custom" style="width:650px;height:150px"><?php echo($page['meta']['custom']); ?></textarea><p class="hint">I.e google page verification, robots, anything else that you may be asked to put in the head.</p></td>
    </tr>				
</table>
</div>
<?php if(!$is_blog) { ?>

<div id="st3-pages" class="qt-content-container" style="display:none;"><h1>Loading</h1></div>
<?php } ?>
</div>
</form>

</div>
<script>
$("#tt2").click();
$("#st1").click();
<?php
if($is_blog) {
//echo('$.fn.loader("blog_posts_list",{post : {id:"'.$id.'"}})');
} else {
echo('$.fn.loader("page_content_list",{post : {id:"'.$id.'"}})');

}

?>



</script>